package BST;

import java.util.ArrayList;

/*
 * This class fulfills the need of use of the Iterator
 */
public class Iterator {
	
	private ArrayList<Integer> list;
	
	public Iterator(){
		list = new ArrayList<Integer>();
	}
	
	public boolean inOrder(Node root){
		
		if(root == null){
			return false;
		}
		inOrder(root.getLeft());
		int value = root.getValue();
		if(value != -1){
			list.add(root.getValue());
		}		
		inOrder(root.getRight());
		return true;
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<Integer> getList(Node root){
		inOrder(root);
		ArrayList<Integer> copyOfList = (ArrayList<Integer>) list.clone();
		list.clear();
		return copyOfList;
	}
}
